<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
#suggest {
	border: 1px solid #999;
	width: 150px;
	margin-left: 110px;
	display: none;
}

.suggest_linke_over {
	background-color: #E8F2FE;
	cursor: hand;
}
</style>
</head>
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script>
	$(function() {
		$("#keyword").keyup(function() {
			$.post("NewsServlet", {
				keyword : $("#keyword").val()
			}, callback);
		});
	});

	function callback(data) {//回调函数
		var sobj = $("#suggest");
		sobj.innerHTML = "";
		var suggest = "";
		var str = data.split(",");
		if (str.length > 0 && str[0].length > 0) {
			for (i = 0; i < str.length; i++) {
				suggest += "<div onmouseover='suggestOver(this);'";
				suggest += " onmouseout='suggestOut(this);'";
				suggest += " onclick='setSearch(this.innerHTML);'";
				suggest += " class='suggest_link'>" + str[i] + "</div>";
			}
			sobj.html(suggest).css("display", "block");

		} else {
			sobj.css("display", "none");
		}
	}
	
	function suggestOver(o){
		o.style.background="lightblue";
	}
	
	function suggestOut(o){
		o.style.background="#FFFFFF";
	}
	
	function setSearch(o){
		$("#keyword").val(o).next().hide();
	}
	
</script>
<body>

	请输入搜索关键字：
	<input type="text" id="keyword" name="keyword" size="30">
	<div id="suggest"></div>
</body>
</html>